Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A11y: enable rule jsx-a11y/anchor-is-valid #56690

Merged
merged 32 commits into from
Oct 21, 2022
Merged

Conversation

eledobleefe
Copy link
Contributor

What this PR does / why we need it:
Enable rule jsx-a11y/anchor-is-valid and fix current errors.

Which issue(s) this PR fixes:

Fixes #55834

Special notes for your reviewer:

@eledobleefe eledobleefe added type/accessibility Accessibility problem / enhancement no-backport Skip backport of PR no-changelog Skip including change in changelog/release notes labels Oct 11, 2022
@eledobleefe eledobleefe added this to the 9.3.0 milestone Oct 11, 2022
@eledobleefe eledobleefe self-assigned this Oct 11, 2022
@@ -87,14 +87,14 @@ export const InputWithAutoFocus = () => {
{inputComponents.map((InputComponent: any, i: number) => (
<InputComponent initialValue="test" key={i} />
))}
<a
<button
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd be careful when changing anything to button as it has submit type by default. Normally its not a big deal, but when used in forms it will trigger a default submit behavior. Therefore I think we'd add type='button' to all the buttons by default (our Button component already has that).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your comment @Clarity-89 😊 I will add type='button'.

Copy link
Contributor

@ashharrison90 ashharrison90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally looks great 🙌

added a couple of minor nits and as previously mentioned we need to:

  • pull out the clearing of these button styles into some reusable/importable function that everywhere can import
  • make sure we add type="button" anywhere we're using the native <button> element to prevent form submission 🙂

<button
role="checkbox"
aria-checked={option.selected}
className={`${highlightClass} ${noStyledButton}`}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think we should use classnames here instead of interpolated strings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ashharrison90. In this case, highlightClasswas already there and its value is set according to a condition so I think this shouldn't be changed. Regarding noStyledButton, we could either let it be or change it to use classnames. What do you think is better?

Copy link
Contributor

@ashharrison90 ashharrison90 Oct 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i think that's fine, i'm saying use the classnames package to apply multiple classes instead of using string interpolation

e.g. classNames={classnames(highlightClass, noStyledButton)}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok. I didn't know about that 🤔 Thank you @ashharrison90!!!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we using cx from emotion for this kind of stuff?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Clarity-89 last thing i remember is we decided we can use either

cx performance is much worse than classnames: #38698

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, makes sense. Didn't know cx had such a poor performance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only thing we have to be careful of is when composing multiple emotion css classes... tbh if the cx performance wasn't like 4-5 times worse we should definitely be using cx everywhere 😅

@eledobleefe eledobleefe requested review from joshhunt, JoaoSilvaGrafana, leventebalogh, codeincarnate and supilee and removed request for a team October 18, 2022 10:47
Copy link
Contributor

@ashharrison90 ashharrison90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me! 🙌

agreed with your suggestion of getting some reviews from a couple of the teams that these changes affect

Copy link
Contributor

@Clarity-89 Clarity-89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Left a minor suggestion.

@@ -121,20 +123,30 @@ export function FilterSection({
return (
<InlineFormLabel key={idx} width="auto" data-testid={testIds.list + idx}>
{fil.tagk} = {fil.type}({fil.filter}), groupBy = {'' + fil.groupBy}
<a onClick={() => editFilter(fil, idx)}>
<button type="button" className={clearButtonStyles(theme)} onClick={() => editFilter(fil, idx)}>
Copy link
Contributor

@Clarity-89 Clarity-89 Oct 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could've done smth like const buttonStyles = useStyles2(clearButtonStyles) at the top and use that throughout the component instead of calling clearButtonStyles in multiple places.

@@ -23,6 +23,8 @@ export function TagSection({
suggestTagValues,
tsdbVersion,
}: TagSectionProps) {
const theme = useTheme2();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same suggestion here.

@grafanabot
Copy link
Contributor

@grafanabot
Copy link
Contributor

Copy link
Contributor

@kevinwcyu kevinwcyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just looked at the CloudWatch changes.

@grafanabot
Copy link
Contributor

@eledobleefe
Copy link
Contributor Author

Hi @grafana/observability-metrics!
I'd really appreciate your feedback as this PR is changing files related to Prometheus and OpenTSDB data sources.
Thanks in advance! 🙂

@gtk-grafana
Copy link
Contributor

Can verify that change to prometheus hint link works fine and is keyboard navigable, can be triggered via or key presses while focused.

image

@bohandley Can you take a look at the openTSDB changes when you have a chance?

Copy link
Contributor

@bohandley bohandley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking over the OpenTSDB sections, filter and tag section button work as intended, LGTM!

@eledobleefe eledobleefe merged commit e402a8f into main Oct 21, 2022
@eledobleefe eledobleefe deleted the eledobleefe/jsx-a11y-55834 branch October 21, 2022 07:13
@leandro-deveikis leandro-deveikis modified the milestones: 9.3.0, 9.3.0-beta1 Nov 14, 2022
@bobrik
Copy link
Contributor

bobrik commented Mar 3, 2023

I think this breaks padding in option selector.

Before:

image

After:

image

This is seemingly because padding: 0px:

image

Is this intentional? It doesn't seem like it is, but maybe I'm missing something.

$ git show e402a8f27d9faabac8181c847b06014ae29af0d5 -- packages/grafana-ui/src/components/Button/Button.tsx
commit e402a8f27d9faabac8181c847b06014ae29af0d5
Author: Laura Fernández <laura.fernandez@grafana.com>
Date:   Fri Oct 21 09:13:32 2022 +0200

    A11y: enable rule jsx-a11y/anchor-is-valid (#56690)

diff --git a/packages/grafana-ui/src/components/Button/Button.tsx b/packages/grafana-ui/src/components/Button/Button.tsx
index 4813543f9c..ae3a903295 100644
--- a/packages/grafana-ui/src/components/Button/Button.tsx
+++ b/packages/grafana-ui/src/components/Button/Button.tsx
@@ -302,3 +302,12 @@ export function getPropertiesForVariant(theme: GrafanaTheme2, variant: ButtonVar
       return getButtonVariantStyles(theme, theme.colors.primary, fill);
   }
 }
+
+export const clearButtonStyles = (theme: GrafanaTheme2) => {
+  return css`
+    background: transparent;
+    color: ${theme.colors.text.primary};
+    border: none;
+    padding: 0;
+  `;
+};

@eledobleefe
Copy link
Contributor Author

Hi @bobrik! We are fixing this as part of this issue #64135. Thank you! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Accessibility: enable rule jsx-a11y/anchor-is-valid
9 participants